package cn.ycl.system.other.study.leetCode;


import org.springframework.aop.support.NameMatchMethodPointcut;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author YuanChangLiang
 * @description
 * @date created in 15:44 2021/11/12
 */


public class TreeSolution {
    public static int coinChange(int[] coins, int amount) {
        //状态分别有零钱的个数，以及零钱的价值
        //dp[i]代表零钱价值为i时的最少硬币个数
        //dp[0] = 0
        //dp[i] = dp[i - 1]
        int[] dp = new int[amount + 1];
        Arrays.fill(dp,Integer.MAX_VALUE - 1);
        dp[0] = 0;
        for (int i = 1; i <= amount; i++) {
            for (int coin : coins) {
                if (i - coin >= 0) {
                    dp[i] = Math.min(dp[i], dp[i - coin] + 1);
                }
            }
            if(dp[i] == Integer.MAX_VALUE){
                dp[i] = 0;
            }
        }
        return dp[amount];
    }


    public static void main(String[] args) {
        int[] coins = {1,2,5};
        int amount = 11;
        int i = coinChange(coins, amount);
        System.out.println(i);
    }
}
